# ========================
# 项目信息
# ========================
# 项目名称
PROJECT_NAME = job-frontend
# 镜像名称
IMAGE_NAME = $(PROJECT_NAME)
# 镜像仓库地址
REGISTRY = hub.jianmucloud.com:5000/jianmu

# ========================
# 构建版本信息
# ========================
# 如果 CI_COMMIT_SHORT_SHA 未定义，使用 'dev' 作为默认标记
ifndef CI_COMMIT_SHORT_SHA
    TAG = dev
else
    TAG = ${CI_COMMIT_SHORT_SHA}
endif

# 用户与组织信息（可选）
ORGANIZATION = 浙江大学 ACES 实验室
MAINTAINER = ai-liuys@outlook.com

# ========================
# 目标规则
# ========================
# 构建镜像
image:
	@echo "Building Docker image for $(PROJECT_NAME)"
	@echo "Organization: $(ORGANIZATION)"
	@echo "Maintainer: $(MAINTAINER)"
	docker build \
	    --label "maintainer=$(MAINTAINER)" \
	    --label "organization=$(ORGANIZATION)" \
	    --label "project=$(PROJECT_NAME)" \
	    -t $(REGISTRY)/$(IMAGE_NAME):$(TAG) .

# 推送镜像
push:
	@echo "Pushing Docker image to $(REGISTRY)"
	docker push $(REGISTRY)/$(IMAGE_NAME):$(TAG)

# 清理本地镜像和临时文件
clean:
	@echo "Cleaning up local Docker images and temporary files..."
	-docker image rm -f $(REGISTRY)/$(IMAGE_NAME):$(TAG)
	-docker image prune -f
	@echo "Clean up completed!"

# 帮助信息
help:
	@echo "Makefile for managing Docker images for $(PROJECT_NAME)"
	@echo ""
	@echo "Available targets:"
	@echo "  image       Build the Docker image with organizational metadata"
	@echo "  push        Push the Docker image to the registry"
	@echo "  clean       Remove the local Docker image and prune dangling images"
	@echo "  help        Show this help message"
	@echo ""
	@echo "Environment Variables:"
	@echo "  TAG         The tag for the Docker image (default: 'dev' or CI_COMMIT_SHORT_SHA)"
	@echo "  REGISTRY    Docker registry URL"
	@echo "  IMAGE_NAME  Docker image name"
	@echo ""
	@echo "Example usage:"
	@echo "  make image"
	@echo "  make push"
	@echo "  make clean"
